<template>
  <div class="goodsListItem" @click="goodsclick">
    <div class="img"><img :src="imgSrc" alt="" /></div>
    <div class="text">
      <p class="title">{{ goodsList.title }}</p>
      <p class="context">
        <span class="price">{{ goodsList.price }}</span
        ><span class="collection">☆{{ goodsList.cfav }}</span>
      </p>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    goodsList: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  computed: {
    imgSrc() {
      //兼容不同数据
      if (this.goodsList.image) {
        return this.goodsList.image;
      } else if (this.goodsList.img) {
        return this.goodsList.img;
      } else if (this.goodsList.show.img) {
        return this.goodsList.show.img;
      }

      // return (this.goodsList.image || this.goodsList.show.img) ||this.goodsList.img
    },
  },
  methods: {
    goodsclick() {
      var id = "";
      if (this.goodsList.iid) {
        id = this.goodsList.iid;
      } else if (this.goodsList.item_id) {
        id = this.goodsList.item_id;
      }
      console.log(id);
      this.$router.push("/details/" + id);
    },
  }

};
</script>
<style scoped>
.goodsListItem {
  width: 0;
  flex: 0 1 48%;
  box-sizing: border-box;
}
.goodsListItem div.img {
  /* height: 230px; */
}

.goodsListItem img {
  width: 100%;
  border-radius: 6px;
}
.goodsListItem div.text {
  font-size: 12px;
  padding-bottom: 5px;
}
.goodsListItem div.text p.title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 100%;
  height: 20px;
  line-height: 20px;
  text-align: center;
}
.goodsListItem div.text p.context {
  text-align: center;
}
.goodsListItem div.text p.context span.price {
  color: #f00;
  margin-right: 5px;
}
</style>